package com.yunfeng.aolin.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yunfeng.aolin.dao.BOMSDAO;
import com.yunfeng.aolin.entity.BOMS;
import com.yunfeng.aolin.service.BOMSService;
import com.yunfeng.common.util.Page;
import com.yunfeng.common.util.PageUtils;

@Service
@Transactional
public class BOMSServiceImpl implements BOMSService {

	@Autowired
	private BOMSDAO bOMSDAO;

	/**
	 * @param id
	 * @return
	 * @see com.yunfeng.aolin.service.BOMSService#get(java.lang.Long)
	 */
	@Override
	public BOMS get(Long id) {
		return bOMSDAO.findOne(id);
	}

	/**
	 * @param bOMS
	 * @see com.yunfeng.aolin.service.BOMSService#saveOrUpdate(com.yunfeng.aolin.entity.BOMS)
	 */
	@Override
	public void saveOrUpdate(BOMS bOMS) {
		bOMSDAO.save(bOMS);
	}

	/**
	 * @param id
	 * @see com.yunfeng.aolin.service.BOMSService#delete(java.lang.Long)
	 */
	@Override
	public void delete(Long id) {
		bOMSDAO.delete(id);
	}

	@Override
	public List<BOMS> findAll() {
		// TODO Auto-generated method stub
		return bOMSDAO.findAll();
	}

	/**
	 * @param page
	 * @return
	 * @see com.yunfeng.aolin.service.BOMSService#findAll(com.ketayao.ketacustom.util.dwz.Page)
	 */
	@Override
	public List<BOMS> findAll(Page page) {
		org.springframework.data.domain.Page<BOMS> springDataPage = bOMSDAO
				.findAll(PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	/**
	 * @param page
	 * @param liaohao
	 * @return
	 * @see com.yunfeng.aolin.service.BOMSService#findByLiaohao(com.ketayao.ketacustom.util.dwz.Page,
	 *      java.lang.String)
	 */
	@Override
	public List<BOMS> findByLiaohao(Page page, String liaohao) {
		org.springframework.data.domain.Page<BOMS> springDataPage = bOMSDAO
				.findByLiaohaoContaining(liaohao,
						PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	/**
	 * 
	 * @param specification
	 * @param page
	 * @return
	 * @see com.yunfeng.aolin.service.BOMSService#findByExample(org.springframework.data.jpa.domain.Specification,
	 *      com.ketayao.ketacustom.util.dwz.Page)
	 */
	@Override
	public List<BOMS> findByExample(Specification<BOMS> specification, Page page) {
		org.springframework.data.domain.Page<BOMS> springDataPage = bOMSDAO
				.findAll(specification, PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}
}
